﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Travel.Data.Inputs
{
    /// <summary>
    /// 基类-输入参数
    /// </summary>
    public abstract class BaseInput
    {
        /// <summary>
        /// 当前登录人
        /// </summary>
        [JsonIgnore]
        public long LoginUserId { get; set; }

        /// <summary>
        /// 基类初始化
        /// </summary>
        protected BaseInput()
        {
            var httpContextAccessor = LocalSericeProvider.Instance.GetService<IHttpContextAccessor>();
            if (httpContextAccessor?.HttpContext?.User.Identity is { IsAuthenticated: true })
            {
                LoginUserId = Convert.ToInt64(httpContextAccessor.HttpContext.User.Claims.FirstOrDefault(
                    p => p.Type.Equals("UserId"))!.Value);
            }

        }
    }
}
